package com.example.bootservice.util;

import com.alibaba.fastjson.JSONObject;
import com.example.bootservice.dto.RepayPlanFileDTO;

import javax.sql.DataSource;
import java.sql.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class JdbcUtil {
    public static void jdbcConn(String sql) throws SQLException {
        //获取数据库连接
        Connection connection = ApplicationContextUtil.getBean(DataSource.class).getConnection();

        Statement statement = connection.createStatement();
        ResultSet rs = statement.executeQuery(sql);
        ResultSetMetaData md = rs.getMetaData();
        int clown = md.getColumnCount();
        while (rs.next()) {
            Map<String,Object> map = new HashMap<>();
            for (int i=1;i<=clown;i++){
                map.put(md.getColumnName(i),rs.getObject(i));
            }
            System.out.println(JSONObject.toJSONString(map));
        }

    }
}
